package CommandMod;

import java.util.ArrayList;
import java.util.List;

public class code {

    // 命令接口
    interface Command {

        void execute();
    }

// 具体命令类：设置命令
    class SettingCommand implements Command {

        private int buttonIndex;
        private int roomIndex;
        private Host host;

        public SettingCommand(int buttonIndex, int roomIndex, Host host) {
            this.buttonIndex = buttonIndex;
            this.roomIndex = roomIndex;
            this.host = host;
        }

        @Override
        public void execute() {
            host.addSetting(buttonIndex, roomIndex);
        }
    }

// 具体命令类：遥控命令
    class RemoteCommand implements Command {

        private Setting setting;

        public RemoteCommand(Setting setting) {
            this.setting = setting;
        }

        @Override
        public void execute() {
            // 假设这里通过蓝牙发送命令
            System.out.println("Sending command to room " + setting.getRoomIndex() + " using button " + setting.getButtonIndex());
        }
    }

// 设置类
    class Setting {

        private int buttonIndex;
        private int roomIndex;

        public Setting(int buttonIndex, int roomIndex) {
            this.buttonIndex = buttonIndex;
            this.roomIndex = roomIndex;
        }

        public int getButtonIndex() {
            return buttonIndex;
        }

        public int getRoomIndex() {
            return roomIndex;
        }
    }

// 主机类，包含设置列表
    class Host {

        private List<Setting> settingList = new ArrayList<>();

        public void addSetting(int buttonIndex, int roomIndex) {
            Setting setting = new Setting(buttonIndex, roomIndex);
            settingList.add(setting);
            System.out.println("Setting added: Button " + buttonIndex + " -> Room " + roomIndex);
        }

        public void remoteLight(int buttonIndex) {
            for (Setting setting : settingList) {
                if (setting.getButtonIndex() == buttonIndex) {
                    new RemoteCommand(setting).execute();
                    break;
                }
            }
        }
    }

}
